/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import static persistencia.DBManagerIngresos.conexion;
import modelo.tabla.Ingresos;
import modelo.MetodosIngresos;


/**
 * En este panel eligiremos mediante un combobox el modelo a borrar
 * @author Kevin
 */
public class JPBorrarIngreso extends javax.swing.JPanel {
    //JPanel jpmc;
    JPBorrarIngreso jpmm;
    Integer delIngresos;
    ArrayList<Ingresos> al;
    /**
     * Creates new form JPMarcaCreacion
     */
        public void actualizarIngresos() throws SQLException, ClassNotFoundException{
        jComboId.removeAllItems();
        MetodosIngresos mti = new MetodosIngresos();
        al = mti.getIngresos();
        for (int i = 0; i < al.size(); i++) {
            jComboId.addItem(al.get(i).getId()); //+al.get(i).getNombre());
        }
    }

    public JPBorrarIngreso() throws SQLException, ClassNotFoundException {
        initComponents();
       actualizarIngresos();

    
        jbBorrarModelo.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String nombreIngreso = (String) jComboId.getSelectedItem();
                Ingresos nIngreso = new Ingresos(nombreIngreso);
                MetodosIngresos mti = null;
                try {
                    mti = new MetodosIngresos();
                    mti.delIngresos(nIngreso);
                    System.out.println ("Ingreso Borrado");
                    actualizarIngresos();
                    JOptionPane.showMessageDialog(null, "Ingreso Borrado");
                }catch (ClassNotFoundException ex){
                    System.err.println ("Error al Borrar Ingreso");
                    ex.printStackTrace();
                } catch (SQLException ex) {
                    Logger.getLogger(JPBorrarIngreso.class.getName()).log(Level.SEVERE, null, ex);
                } 
                
                }
        });
        
    }

    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlNombreMarca = new javax.swing.JLabel();
        jbBorrarModelo = new javax.swing.JButton();
        jComboId = new javax.swing.JComboBox();

        jlNombreMarca.setText("Borrar Ingreso:");

        jbBorrarModelo.setText("Borrar");
        jbBorrarModelo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jlNombreMarca)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboId, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(166, 166, 166)
                        .addComponent(jbBorrarModelo)))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlNombreMarca))
                .addGap(18, 18, 18)
                .addComponent(jbBorrarModelo)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox jComboId;
    private javax.swing.JButton jbBorrarModelo;
    private javax.swing.JLabel jlNombreMarca;
    // End of variables declaration//GEN-END:variables
}
